﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WorkflowCore.Interface;
using WorkflowCore.Models;

namespace Workflow2211A.Consol.Steps
{
    /// <summary>
    /// 
    /// </summary>
    public class WaitForStep : StepBodyAsync
    {
        public override async Task<ExecutionResult> RunAsync(IStepExecutionContext context)
        {
            //ExecutionPointer:节点
            //Step:步骤

            //判断当前的节点是否有审批事件
            if (!context.ExecutionPointer.EventPublished)
            {
                Console.WriteLine("等待审批");
                //创建一个审批等待事件
                return ExecutionResult.WaitForEvent("MyEvent",context.Workflow.Id,DateTime.Now);
            }
            //获取审批意见
            var auditRemark = context.ExecutionPointer.EventData.ToString();

            Console.WriteLine("您的审批意见是：" + auditRemark);
            //如果审批了，则进入下一个节点
            return ExecutionResult.Next();
        }
    }
}
